package com.manage.project.biz.controller;

import java.util.ArrayList;
import java.util.List;

import com.manage.common.utils.poi.ExcelUtil;
import com.manage.framework.aspectj.lang.annotation.Log;
import com.manage.framework.aspectj.lang.enums.BusinessType;
import com.manage.framework.web.controller.BaseController;
import com.manage.framework.web.domain.AjaxResult;
import com.manage.framework.web.page.TableDataInfo;
import com.manage.project.biz.domain.BizGonglu;
import com.manage.project.biz.domain.BizJidianjiankongyutongxinqingjie;
import com.manage.project.biz.domain.BizSuidao;
import com.manage.project.biz.service.IBizGongluService;
import com.manage.project.biz.service.IBizJidianjiankongyutongxinqingjieService;
import com.manage.project.biz.service.IBizSuidaoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 【请填写功能名称】Controller
 *
 * @author ruoyi
 * @date 2022-06-02
 */
@RestController
@RequestMapping("/biz/jidianjiankongyutongxinqingjie")
public class BizJidianjiankongyutongxinqingjieController extends BaseController
{
    @Autowired
    private IBizJidianjiankongyutongxinqingjieService bizJidianjiankongyutongxinqingjieService;

    @Autowired
    private IBizSuidaoService bizSuidaoService;

    @Autowired
    private IBizGongluService bizGongluService;

    /**
     * 查询【请填写功能名称】列表
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie)
    {
        startPage();
        List<BizJidianjiankongyutongxinqingjie> list = bizJidianjiankongyutongxinqingjieService.selectBizJidianjiankongyutongxinqingjieList(bizJidianjiankongyutongxinqingjie);
        return getDataTable(list);
    }

    @GetMapping("/level")
    public TableDataInfo getLevel(BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie)
    {
        List<String> list = new ArrayList<>();

        String tunnelName = bizJidianjiankongyutongxinqingjie.getField1();
        if (tunnelName == null){
            return getDataTable(list);
        }
        BizSuidao bizSuidao = new BizSuidao();
        bizSuidao.setField2(tunnelName);
        List<BizSuidao> listSuidao = bizSuidaoService.selectBizSuidaoList(bizSuidao);
        long tunnelLength = Long.parseLong(listSuidao.get(0).getField5());// 隧道长度
        long tunnelCars = Long.parseLong(listSuidao.get(0).getField18()); // 隧道年日均交通量
        BizGonglu bizGonglu = new BizGonglu();
        bizGonglu.setField2(listSuidao.get(0).getField22());
        List<BizGonglu> listBizGonglu = bizGongluService.selectBizGongluList(bizGonglu);
        String gongluLevel = listBizGonglu.get(0).getField9(); // 公路等级
        if (gongluLevel.equals("一级")){
          if (tunnelCars>=10001){
              if (tunnelLength>3000){
                  list.add("一级");
              } else if (tunnelLength>1000 && tunnelLength<=3000){
                  list.add("一级");
              } else if (tunnelLength>500 && tunnelLength<=1000){
                  list.add("一级");
              } else if (tunnelLength<=500){
                  list.add("二级");
              }
          } else if (tunnelCars>=5001){
              if (tunnelLength>3000){
                  list.add("一级");
              } else if (tunnelLength>1000 && tunnelLength<=3000){
                  list.add("一级");
              } else if (tunnelLength>500 && tunnelLength<=1000){
                  list.add("二级");
              } else if (tunnelLength<=500){
                  list.add("二级");
              }
          } else {
              if (tunnelLength>3000){
                  list.add("一级");
              } else if (tunnelLength>1000 && tunnelLength<=3000){
                  list.add("二级");
              } else if (tunnelLength>500 && tunnelLength<=1000){
                  list.add("二级");
              } else if (tunnelLength<=500){
                  list.add("二级");
              }
          }
        } else {
            if (tunnelCars>=10001){
                if (tunnelLength>3000){
                    list.add("一级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("二级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("二级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            } else if (tunnelCars>=5001){
                if (tunnelLength>3000){
                    list.add("二级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("二级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("三级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            } else {
                if (tunnelLength>3000){
                    list.add("二级");
                } else if (tunnelLength>1000 && tunnelLength<=3000){
                    list.add("三级");
                } else if (tunnelLength>500 && tunnelLength<=1000){
                    list.add("三级");
                } else if (tunnelLength<=500){
                    list.add("三级");
                }
            }
        }
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @Log(title = "监控与通信设施清洁维护", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie)
    {
        List<BizJidianjiankongyutongxinqingjie> list = bizJidianjiankongyutongxinqingjieService.selectBizJidianjiankongyutongxinqingjieList(bizJidianjiankongyutongxinqingjie);
        ExcelUtil<BizJidianjiankongyutongxinqingjie> util = new ExcelUtil<BizJidianjiankongyutongxinqingjie>(BizJidianjiankongyutongxinqingjie.class);
        return util.exportExcel(list, "监控与通信设施清洁维护记录");
    }
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:export')")
//    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie) throws IOException {
//        List<BizJidianjiankongyutongxinqingjie> list = bizJidianjiankongyutongxinqingjieService.selectBizJidianjiankongyutongxinqingjieList(bizJidianjiankongyutongxinqingjie);
//        ExcelUtil<BizJidianjiankongyutongxinqingjie> util = new ExcelUtil<BizJidianjiankongyutongxinqingjie>(BizJidianjiankongyutongxinqingjie.class);
//        util.exportExcel(response, list, "监控与通信设施清洁记录数据");
//    }

    /**
     * 获取【请填写功能名称】详细信息
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(bizJidianjiankongyutongxinqingjieService.selectBizJidianjiankongyutongxinqingjieById(id));
    }

    /**
     * 新增【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:add')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie)
    {
        return toAjax(bizJidianjiankongyutongxinqingjieService.insertBizJidianjiankongyutongxinqingjie(bizJidianjiankongyutongxinqingjie));
    }

    /**
     * 修改【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:edit')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizJidianjiankongyutongxinqingjie bizJidianjiankongyutongxinqingjie)
    {
        return toAjax(bizJidianjiankongyutongxinqingjieService.updateBizJidianjiankongyutongxinqingjie(bizJidianjiankongyutongxinqingjie));
    }

    /**
     * 删除【请填写功能名称】
     */
//    @PreAuthorize("@ss.hasPermi('biz:jidianjiankongyutongxinqingjie:remove')")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizJidianjiankongyutongxinqingjieService.deleteBizJidianjiankongyutongxinqingjieByIds(ids));
    }
}
